Skip to content

Conversation

@rcosta358
Copy link
Collaborator

This PR fixes a small issue where if we had a syntax error in LiquidJava annotation other than @Refinement, a NoSuchMethodException was thrown because when trying to get the source location of the annotation, I only considered @Refinement annotations. Also added a test case with a syntax error in a state refinement that previously would throw an exception.

@rcosta358 rcosta358 self-assigned this Feb 6, 2026
@rcosta358 rcosta358 added the bug Something isn't working label Feb 6, 2026
}).findFirst().map(CtElement::getPosition).orElse(element.getPosition());
public static SourcePosition getAnnotationPosition(CtElement element, String refinement) {
return element.getAnnotations().stream()
.filter(a -> isLiquidJavaAnnotation(a) && hasRefinementValue(a, "\"" + refinement + "\"")).findFirst()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this work well if the error is just on the "to" of a state refinement?

Copy link
Collaborator Author

@rcosta358 rcosta358 Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, It can be in either the value field of a @Refinement or in the from or to of a @StateRefinement. This logic is simply to get the position of the annotation that actually contains the refinement that caused error, e.g. we could have multiple state refinements and we want to get the position of the right one.

private static boolean hasRefinementValue(CtAnnotation<?> annotation, String refinement) {
Map<String, ?> values = annotation.getValues();
return Stream.of("value", "to", "from")
.anyMatch(key -> refinement.equals(String.valueOf(values.get(key))));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants